<?php

namespace Modules\Admin\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;

class Admin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $version = '?v='.env('STATIC_VERSION',1);
        Blade::directive('css',function($expression) use($version){
//            $sPath = trim($expression,'\'').$version;
            $sPath = $expression.$version;

            $url = '<link rel="stylesheet" href="admin/'.$sPath.'">';
            return $url;
        });
        Blade::directive('js',function($expression)use($version){
//            $sPath = trim($expression,'\'').$version;
            $sPath = $expression.$version;
            $url = '<script type="text/javascript" src="admin/'.$sPath.'"></script>';
            return $url;
        });
//        Blade::directive('img',function($expression)use($version){
//            $sPath = trim($expression,'\'').$version;
//            $url = 'admin/img/'.$sPath;
//            return $url;
//        });
        return $next($request);
    }

}
